package cn.tedu.weibo2.service.impl;

import cn.tedu.weibo2.mapper.WeiboMapper;
import cn.tedu.weibo2.pojo.dto.WeiboDTO;
import cn.tedu.weibo2.pojo.entity.Weibo;
import cn.tedu.weibo2.pojo.vo.WeiboDetailVO;
import cn.tedu.weibo2.pojo.vo.WeiboIndexVO;
import cn.tedu.weibo2.service.WeiboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WeiboServiceImpl implements WeiboService {
    @Autowired
    private WeiboMapper weiboMapper;

    @Override
    public void insert(WeiboDTO weiboDTO) {
        Weibo weibo=new Weibo();
        BeanUtils.copyProperties(weiboDTO,weibo);
        weibo.setCreated(new Date());
        weiboMapper.insert(weibo);
    }

    @Override
    public List<WeiboIndexVO> list() {
       return weiboMapper.select();
    }

    @Override
    public List<WeiboDetailVO> selectByIndex(Long id) {
        return weiboMapper.selectByIndex(id);
    }

    @Override
    public void deleteById(Long id) {
        weiboMapper.deleteByWeiboId(id);
    }

    @Override
    public WeiboDetailVO detailWeibo(Long weiboId) {
        return weiboMapper.detailWeibo(weiboId);
    }

}
